package nix.generic;

import java.util.Arrays;

public class TestGenericMethod {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		Integer[] arr1 = { 1, 2, 3, 4, 5, 6 };
		System.out.println(Arrays.toString(arr1));
		swap(arr1, 1, 3);
		System.out.println(Arrays.toString(arr1));

		String[] arr2 = { "aa", "bb", "cc", "dd", "ee", "ff" };
		System.out.println(Arrays.toString(arr2));
		swap(arr2, 1, 3);
		System.out.println(Arrays.toString(arr2));
	}

	/**
	 * 泛型方法
	 * 
	 * @param arr
	 * @param i
	 * @param j
	 */
	public static <T> void swap(T[] arr, int i, int j) {
		T tmp = arr[i];
		arr[i] = arr[j];
		arr[j] = tmp;
	}
}
